package com.nameless.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nameless.dao.BrandDao;
import com.nameless.entity.Brand;
import com.nameless.entity.CarTypeConfigDetails;
import com.nameless.entity.Menu;
import com.nameless.service.BrandService;
import com.nameless.vo.BrandVo;
import com.nameless.vo.HeaderVo;
import com.nameless.vo.Result;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author keluoyisi
 * @program: car-parent
 * @description: 品牌业务实现
 * @date 2023-02-27 15:49:01
 */
@Service
@SuppressWarnings("all")
public class BrandServiceImpl extends ServiceImpl<BrandDao, Brand> implements BrandService {
    @Autowired
    private BrandDao brandDao;


    @Override
    public Result selectBrandAll(BrandVo brandVo) {
        Page<Object> page = PageHelper.startPage(brandVo.getPageNum(), brandVo.getPageSize());
        QueryWrapper<Brand> wrapper =null;
        if (brandVo.getName()!=null){
             wrapper = new QueryWrapper<>();
            wrapper.like("name",brandVo.getName());
        }
        List<Brand> brands = brandDao.selectList(wrapper);

        PageInfo<Brand> info = new PageInfo<>(brands);
        return new Result(200,"成功",info);
    }

    @Override
    public Result insertBrand(Brand brand) {
        int insert = brandDao.insert(brand);
        return new Result(200,"成功");
    }

    @Override
    public Result updateBrand(Brand brand) {
        int i = brandDao.updateById(brand);
        return new Result(200,"成功");
    }

    @Override
    public Result deleteById(Integer id) {
        int i = brandDao.deleteById(id);
        return new Result(200,"成功");
    }

    @Override
    public Result listBand() {
        List<Brand> brands = brandDao.selectList(null);
        ArrayList<HeaderVo> headerVos = new ArrayList<>();
        for (Brand brand : brands) {
            HeaderVo headerVo = new HeaderVo();
            headerVo.setText(brand.getName());
            headerVo.setValue(brand.getId());
            headerVos.add(headerVo);
        }
        return new Result(200,"成功",headerVos);
    }


}
